package com.yjhb.android.sbz.mvp.login;

import com.yjhb.android.sbz.entity.UserInfo;
import com.yjhb.android.sbz.http.HttpObserver;
import com.yjhb.android.sbz.http.HttpTool;

/**
 * 创建者 zx
 * 创建时间 2020/11/23 16:31
 */
public class MsgLoginPresenter extends LoginPresenter<MsgLoginView> {
    private final String TAG = "MsgLoginPresenter";

    public MsgLoginPresenter(MsgLoginView msgLoginView) {
        super(msgLoginView);
    }

    @Override
    protected void onDestroy() {

    }

    public void login(String tel,String code,String parentId,String device){
        if (view != null) {
            view.loggingIn();
        }
        HttpTool.request(model.msgLogin(tel,code,parentId,device,"1"), new HttpObserver<UserInfo>() {
            @Override
            public void onResult(UserInfo data) {
                if (view != null) {
                    view.onLoginSuccess(data);
                }
            }

            @Override
            public void onError(int code, String msg) {
                if (view != null) {
                    view.onFailure(code, msg);
                }
            }
        });
    }


    /**
     * 获取手机验证码
     *
     * @param tel
     */
    public void getTelCode(String tel) {
        HttpTool.request(model.getMsgCode(tel), new HttpObserver<String>() {
            @Override
            public void onResult(String data) {
                if (view != null) {
                    view.onMsgSend();
                }
            }

            @Override
            public void onError(int code, String msg) {
                if (view != null) {
                    view.onFailure(code, msg);
                }
            }
        });
    }

}
